import { Injectable } from '@nestjs/common';
import * as svgCaptcha from 'svg-captcha';
import { nanoid } from 'nanoid';

@Injectable()
export class SystemLoginService {
  /**
   * 验证码
   */
  async captcha() {
    const captcha = svgCaptcha.create({
      ignoreChars: 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM',
      noise: 1,
      background: '#cc9966',
    });

    const result = {
      captchaId: nanoid(),
      data: captcha.data.replaceAll(/"/g, "'"),
    };

    console.log(result.captchaId);

    return result;
  }
}
